package com.ws.LibraryMGSystem.test;

import com.ws.LibraryMGSystem.dao.BookDao;
import com.ws.LibraryMGSystem.dao.impl.BookDaoImpl;
import com.ws.LibraryMGSystem.entity.AdminUser;
import com.ws.LibraryMGSystem.entity.Book;
import com.ws.LibraryMGSystem.entity.NormalUser;
import com.ws.LibraryMGSystem.entity.User;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

/**
 * @author 王硕
 * @version jdk21
 * @className Test
 * @description
 * @date 2024/11/22 15:58
 */
public class BookMgr {

    private static final Scanner scanner = new Scanner(System.in);
    private static BookDao bookDao = new BookDaoImpl();
    private static  Map<String, User> users = new HashMap<>();
    private static  Map<String, Book> books = new HashMap<>();

    public void initializedata() {
        users.put("张三", new AdminUser().setAuId(1).setName("张三").setPassword(1234));
        users.put("李四", new NormalUser().setNuId(0).setName("李四").setPassword(1234));
        books.put("三国演义", new Book().setBookName("三国演义").setBookAuthor("罗贯中").setInventory(50).setPrice(100.00));
        books.put("红楼梦", new Book().setBookName("红楼梦").setBookAuthor("曹雪芹").setInventory(20).setPrice(120.00));
        books.put("西游记", new Book().setBookName("西游记").setBookAuthor("吴承恩").setInventory(70).setPrice(70.00));
        books.put("水浒传", new Book().setBookName("水浒传").setBookAuthor("施耐庵").setInventory(100).setPrice(60.00));
    }
    public <User> User login(){
        System.out.print("请输入用户名: ");
        String username = scanner.nextLine();
        System.out.print("请输入密码: ");
        int password = scanner.nextInt();
        scanner.nextLine();
        User currentUser = users.get(username);
        if (currentUser.getPassword()==password){
            System.out.println("登录成功");
            return currentUser;
        }else {
            System.out.println("登陆失败");
            System.exit(1);
        }
        return null;
    }
    public  void <User> menu<User>(){

        boolean result = true;
        do {
            System.out.println("请选择操作: 1.查看所有图书信息 2.查看指定图书信息 3.添加图书信息");
            int choice = scanner.nextInt();
            scanner.nextLine();
            switch (choice) {
                case 1:
                    System.out.println("111111");
                    break;
                case 2:
                    System.out.println("22222");
                    break;
                case 3:
                    System.out.println("333333");
                    break;
                default:
                    System.out.println("无效的选择！");
                    result = false;
                    break;
            }
        }while (result);
    }
    public void test() {
        initializedata();
        menu(login());
    }
}
